package cn.wolfcode.wms.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.wolfcode.wms.domain.Department;
import cn.wolfcode.wms.mapper.DepartmentMapper;
import cn.wolfcode.wms.query.PageResult;
import cn.wolfcode.wms.query.QueryObject;
import cn.wolfcode.wms.service.IDepartmentService;

@Service
public class DepartmentServiceImpl implements IDepartmentService {

	@Autowired
	private DepartmentMapper mapper;
	
	@Override
	public void save(Department department) {
		mapper.save(department);
	}

	@Override
	public void delete(Long id) {
		mapper.delete(id);
	}

	@Override
	public void update(Department department) {
		mapper.update(department);
	}

	@Override
	public Department get(Long id) {
		return mapper.get(id);
	}

	@Override
	public List<Department> list() {
		return mapper.list();
	}

	@Override
	public PageResult query(QueryObject qo) {
		int totalCount = mapper.queryForCount(qo);
		if (totalCount == 0) {
			return new PageResult(qo.getPageSize());
		}
		List<Department> listData= mapper.queryForList(qo);
		return new PageResult(qo.getCurrentPage(),qo.getPageSize(), listData, totalCount);
	}

}
